const { STATUS_CODE } = require('../../../constants/index');
const validateMoment = async (ctx, next) => {
  const moment = ctx.request.body;
  if (!moment.content) {
    ctx.app.emit('error', new Error(STATUS_CODE.PARAMS_ERROR), ctx);
    return;
  }
  if (moment.content.length > 500) {
    const error = {
      code: STATUS_CODE.FIELD_LENGTH_ERROR,
      field: 'content',
      message: 'content length must be <= 500',
    };
    ctx.app.emit('error', new Error(JSON.stringify(error)), ctx);
    return;
  }
  await next();
};

module.exports = validateMoment;
